using System;
using System.Collections.Generic;
using System.Text;

namespace Nix.PBeM.Engine.DataTypes.Basic
{
	/// <summary>
	/// Day interval.
	/// </summary>
	public class DayInterval
	{
		private int start = 0;

		/// <summary>
		/// Gets the start.
		/// </summary>
		/// <value>The start.</value>
		public int Start
		{
			get { return start; }
		}

		private int? end = null;

		/// <summary>
		/// Gets the end.
		/// </summary>
		/// <value>The end.</value>
		public int? End
		{
			get { return end; }
			set
			{
				if (value < this.start)
					throw new ArgumentOutOfRangeException("End day can not be less then start day.");
				end = value;
			}
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="DayInterval"/> class.
		/// </summary>
		/// <param name="start">The start day.</param>
		public DayInterval(int start)
		{
			this.start = start;
		}

		/// <summary>
		/// Check if specified day is in current interval.
		/// </summary>
		/// <param name="day">The day.</param>
		/// <returns></returns>
		public bool IncludesDay(int day)
		{
			return (this.Start <= day && ( ! this.End.HasValue || this.End.Value >= day));
		}
	}
}
